package models

import (
	"fmt"
	"github.com/beego/beego/v2/client/orm"
)

type ServiceSimpleVOModel struct {
	ServiceID         int     `json:"serviceID" orm:"column(service_ID)"`
	ServiceName       string  `json:"serviceName" orm:"column(service_name)"`
	ServiceScore      int     `json:"serviceScore" orm:"column(service_score)"`
	ServiceAssessment string  `json:"serviceAssessment" orm:"column(service_assessment)"`
	ServiceStatus     int     `json:"serviceStatus" orm:"column(service_status)"`
	ServiceBudget     float32 `json:"serviceBudget" orm:"column(service_budget)"`
	CustomerName      string  `json:"customerName" orm:"column(customer_name)"`
	CustomerID        int     `json:"customerID" orm:"column(customer_ID)"`
}

// GetAllServiceList 查询所有服务
func GetAllServiceList(from, to int64) ([]ServiceSimpleVOModel, int64) {
	o := orm.NewOrm()
	var services []ServiceSimpleVOModel
	var total int64
	num, err := o.Raw("select ser.service_name,ser.service_score,ser.service_assessment,service_status,ser.service_budget,cus.customer_name,ser.customer_ID from services ser left join customers cus on ser.customer_ID = cus.customer_ID order by service_status limit ?,?", from, to).QueryRows(&services)
	err = o.Raw("select count(*) from services ser left join customers cus on ser.customer_ID = cus.customer_ID").QueryRow(&total)
	if err == nil {
		fmt.Println(services, total)
		return services, total
	} else {
		return []ServiceSimpleVOModel{}, num
	}
}
